package org.ricks.condition1.test;

import org.ricks.condition1.entity.Achievement;
import org.ricks.condition1.entity.Task;
import org.ricks.condition1.event.ProgressUpdatedEvent;
import org.ricks.ioc.anno.Bean;
import org.ricks.ioc.event.anno.EventReceiver;
import org.ricks.orm.OrmContext;

@Bean
public class ProgressUpdateListener {

    @EventReceiver
    public void handleTaskProgress(ProgressUpdatedEvent<Task> event) {
        Task task = event.context();
        task.setCurrentValue(event.currentValue());
//        OrmContext.me().update(task);
        System.out.println("任务进度已更新：" + task.getTaskId() + " -> " + task.getCurrentValue());
    }


    // 成就进度监听
    @EventReceiver
    public void handleAchievementProgress(ProgressUpdatedEvent<Achievement> event) {
        Achievement achievement = event.context();
        achievement.setCurrentValue(event.currentValue());
//        OrmContext.me().update(achievement);
    }
}
